1330740 ランダム
 HOME | DIARY | PROFILE 【フォローする】 【ログイン】

さすらいのプログラマ

さすらいのプログラマ

DebugConsole

■DebugConsole.h
#ifndef    __DEFINE_DEBUG_CONSOLE__
#define    __DEFINE_DEBUG_CONSOLE__
#include<windows.h>
#include<stdio.h>
#include<fcntl.h>

int CreateDebugConsole();
void ReleaseDebugConsole(int fd);

extern int g_fd;
#endif // __DEFINE_DEBUG_CONSOLE__

■DebugConsole.c
#include"DebugConsole.h"

int g_fd;

int CreateDebugConsole() {
  HANDLE hStdout;
  int fd;
  FILE *fp;
  
  AllocConsole();
  hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  fd = _open_osfhandle((long)hStdout, _O_TEXT);
  fp = _fdopen(fd, "w");
  *stdout = *fp;
  setvbuf(stdout, NULL, _IONBF, 0);

  return fd;
}

void ReleaseDebugConsole(int fd) {
  _close(fd);
  FreeConsole();
}


※転載禁止です。


© Rakuten Group, Inc.